#include "stdafx.h"
#include "export.h"
#include "functions.h"

#define NORTIFIERLIB_EXPORT

extern HWND g_hWndCaller;
extern HHOOK   g_hHook ;

extern "C"
BOOL
__declspec(dllexport)
SetKeyKook( 
    BOOL bInstall, 
    DWORD dwThreadId /* = 0  */, 
    HWND hWndCaller /* = NULL */ )
{
    BOOL bResult = FALSE;

    do 
    {
        g_hWndCaller = hWndCaller;
        if( !bInstall )
        {
            bResult = ::UnhookWindowsHookEx( g_hHook );
            g_hHook = NULL;
            break;
        }
       g_hHook = ::SetWindowsHookEx( WH_KEYBOARD,
                                                          KeyHookProc,
                                                         ModuleFromAddress( KeyHookProc ),
                                                          dwThreadId );
        bResult = ( g_hHook != NULL );
        
    } while ( FALSE );

    return  bResult;
}